package cn.devices.service.impl;

import cn.devices.entity.TbType;
import cn.devices.mapper.TbTypeMapper;
import cn.devices.service.TbTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 设备类别表 服务实现类
 * </p>
 *
 * @author 秋水浮萍
 * @since 2021-02-07
 */
@Service
public class TbTypeServiceImpl implements TbTypeService {

    @Autowired
    private TbTypeMapper mapper;

    @Override
    public int tbTypeAdd(TbType tbType) {
        return mapper.tbTypeAdd(tbType);
    }

    @Override
    public int tbTypeUpdate(TbType tbType) {
        return mapper.tbTypeUpdate(tbType);
    }

    @Override
    public int tbTypeID(String typeIdOld, String tbTypeIdNew) {
        return mapper.tbTypeID(typeIdOld, tbTypeIdNew);
    }

    @Override
    public int tbTypeDelete(String typeId) {
        return mapper.tbTypeDelete(typeId);
    }

    @Override
    public TbType tbType(String typeId) {
        return mapper.tbType(typeId);
    }

    @Override
    public List<TbType> tbTypeList() {
        return mapper.tbTypeList();
    }

    @Override
    public PageInfo<TbType> tbTypePage(int pageIndex, int pageSize) {
        PageHelper.startPage(pageIndex, pageSize);
        List<TbType> tbTypeList = mapper.tbTypeList();
        for (TbType tbType : tbTypeList){
            if ("1".equals(tbType.getTypeLevel())){
                tbType.setTypeLevel("内部借用");
            }else if ("2".equals(tbType.getTypeLevel())){
                tbType.setTypeLevel("可借出公司");
            }else {
                tbType.setTypeLevel("保密设备");
            }
        }
        return new PageInfo<>(tbTypeList);
    }
}
